home *** CD-ROM | disk | FTP | other *** search
- Path: gambier.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++
- Subject: Re: C/C++ knocks the crap out of Ada
- Date: 15 Mar 1996 09:48:49 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4icai1INN608@gambier.ugrad.cs.ubc.ca>
- References: <JSA.96Feb16135027@organon.com> <4hm6lo$eln@fred.netinfo.com.au> <4hml8s$a1q@solutions.solon.com> <DoBIoL.1JC@world.std.com>
- NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
-
- In article <DoBIoL.1JC@world.std.com>,
- Robert A Duff <bobduff@world.std.com> wrote:
- >In article <4hml8s$a1q@solutions.solon.com>,
- >Peter Seebach <seebs@solutions.solon.com> wrote:
- >>Certainly. A C implementation is free to be an interpreter that emulates
- >>every bit of every value and checks for arbitrary programming errors.
- >>
- >>There is no restriction that an implementation may not offer range checking,
- >>and many already do have stricter type checking than the standard requires.
- >
- >But C doesn't have any syntax for defining the range of an int, except:
- >
- > int x; /* x is always between 1 and 10 */
- >
- >So how can a C implementation check this range, without extending the
- >syntax of the language? There are many other examples.
-
- Quite frankly, you can't do it. If the integer is not used as any sort of array
- index, you don't know what the range is. Here are some alternatives:
-
- 1. Use an enumerated type. Drawback: it's not an arithmetic type.
- Incrementing an enumerated variable, for instance, is a no no.
- An expression involving an enumerated type promotes it to an
- int, and can't be assigned back to the enumerated type.
-
- 2. assert() macros. This is ugly, and places the burden on the programmer.
- It does work, however, and _is_ standardized.
-
- Specifying ranges for integers is something that I dearly miss about Modula 2.
- (But that's about it...) It really is a significant feature.
- --
-
-